/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

/**
 *
 * @author Francisco
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConexionDAO {
    
    private static String login = "tsb";
    private static String pass="1234";
    private static String url = "jdbc:derby: ./TSBMonopolyDB";
    private static Connection conn = null;
     
    /**
     * Metodo utilizado para abrir una conexion
     * @return Conexion abierta
     */ 
     public static Connection conectarBD() {
        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            conn = DriverManager.getConnection(url, login, pass);
            if (conn != null) {
                System.out.println("Conexión a base de datos " + url + " ... Ok");
            }
        return conn;
        }
        catch (SQLException ex) {
            System.out.println("Hubo un problema al intentar conectarse con la base de datos " + url + " " + ex.getSQLState());
            ex.printStackTrace();
        }
        catch (ClassNotFoundException ex) {
            System.out.println(ex);
        }
        catch (Exception ex) {
        }
        return null;
    }
     
    /**
     * Metodo utilizado para cerrar una conexion abierta
     * @param c Conexion abierta a cerrar
     */ 
    public static void desconectarBD(Connection c) {
        try {
            c.close();
            System.out.println("Se desconectó");
        }
        catch (SQLException ex) {
            System.out.println("No se pudo cerrar");
        }
    }   
    
    
}

